#include <iostream>
#include <algorithm>

using namespace std;

const int N = 2e5 + 10;
struct node
{
    int begin,end;
}a[N];

bool cmp(const node& x,const node& y)
{
    if(x.end != y.end)
    {
        return x.end < y.end;
    }
    return x.begin < y.begin;
}

int main() {
    int n;
    cin >> n;
    for(int i = 0;i < n;i++)
    {
        cin >> a[i].begin >> a[i].end;
    }
    sort(a,a + n,cmp);
    int sum = 1;
    int end = a[0].end;
    for(int i = 1;i < n;i++)
    {
        if(a[i].begin >= end)
        {
            end = a[i].end;
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}
// 64 位输出请用 printf("%lld")